import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;

public class JGI_Keylistener implements KeyListener 
{
	JAPI_SocketOutputStream JGI_commandstream;
	JAPI_SocketOutputStream JGI_actionstream;
	int JGI_id;		
	int current_char=0;
	int current_code=0;
	int debuglevel=0;	
	
	public JGI_Keylistener(int object_id,  JAPI_SocketOutputStream command, JAPI_SocketOutputStream action ) 
	throws IOException
	{
		JGI_commandstream=command;
		JGI_actionstream=action;
		JGI_id = object_id;		
		JGI_commandstream.sendInt(JGI_id);
	}
	

	public void getchar() throws IOException
	{
		JGI_commandstream.sendInt(current_char);
	} 

	public void getcode() throws IOException
	{
		JGI_commandstream.sendInt(current_code);
	} 


	public void keyPressed(KeyEvent e)
	{
		if(debuglevel > 1) System.out.println("Key Event in Object : "+this.JGI_id);	
		try
		{	
			JGI_actionstream.sendInt(JGI_id);
		}	
		catch(IOException exce) {}		
		current_char=(int)e.getKeyChar();
		current_code=e.getKeyCode();
	}

	public void keyReleased(KeyEvent e)
	{
		//   klappt nicht richtig (Bug in 1.1 ?)
	}

	public void keyTyped(KeyEvent e) 
	{
		//   klappt nicht richtig (Bug in 1.1 ?)
	}

	public void setdebuglevel(int level)
	{
		debuglevel=level;
	}

}